const express = require('express');
const router = express.Router();
const url = require('url');

// 判断用户是否登录
router.use((req, res, next)=>{
  // 获取不包含参数的纯路径
  let pathname = url.parse(req.url).pathname;
  // console.log(pathname);
  if(req.session.userinfo && req.session.userinfo.username){
    next();
  }else{
    //排除 /admin/login、/admin/login/verify
    if(pathname=='/login' || pathname=='/login/doLogin' 
       || pathname=='/login/verify'){
        next();
    }else{
      res.redirect('/admin_express/login');
    }
    // next();
  }
});

const main = require('./admin/main');
const manager = require('./admin/manager');
const nav = require('./admin/nav');
const login = require('./admin/login');
const focus = require('./admin/focus');
const articleCate = require('./admin/articleCate');
const article = require('./admin/article');
const setting = require('./admin/setting');

router.use('/', main);
router.use('/manager', manager);
router.use('/nav', nav);
router.use('/login', login);
router.use('/focus', focus);
router.use('/articleCate', articleCate);
router.use('/article', article);
router.use('/setting', setting);


module.exports = router;